package com.woniuxy.commons.handler;

import com.woniuxy.commons.util.ResponseResult;
import com.woniuxy.commons.util.ResultStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 全局异常处理
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public ResponseResult runtime(RuntimeException e) {
        log.warn("全局异常处理器捕获到:" + e);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setStatus(ResultStatus.FAIL);
        responseResult.setCode(500);
        responseResult.setMsg("服务器异常：" + e.getMessage() );
        return  responseResult;
    }
}
